<template>
  <view class="category">
    <view
      class="category-item"
      hover-class="none"
      url="/pages/detail/detail"
      @click="weixinSaomaUrl"
    >
      <image class="icon" src="/static/images/saoma.png"></image>
      <text class="text">扫码换电</text>
    </view>
    <view class="category-item" hover-class="none" url="/pages/detail/detail">
      <image class="icon" src="/static/images/wodecheliang.png"></image>
      <text class="text">我的车辆</text>
    </view>
    <view class="category-item" hover-class="none" url="/pages/detail/detail" @click="openCharging">
      <image class="icon" src="/static/images/chongdianjilu.png"></image>
      <text class="text">充电记录</text>
    </view>
    <view class="category-item" hover-class="none" url="/pages/detail/detail">
      <image class="icon" src="/static/images/huandianjilu.png"></image>
      <text class="text">换电记录</text>
    </view>
    <view class="category-item" hover-class="none" url="/pages/detail/detail">
      <image class="icon" src="/static/images/chongdianjiaocheng.png"></image>
      <text class="text">充电教程</text>
    </view>
    <view class="category-item" hover-class="none" url="/pages/detail/detail">
      <image class="icon" src="/static/images/huandianjiaocheng.png"></image>
      <text class="text">换电教程</text>
    </view>
  </view>
</template>
<script setup lang="ts">
import type { CategoryItem } from '@/types/home'
import { Static } from 'vue'

// 定义 props 接收数据
// defineProps<{
//   list: CategoryItem[]
// }>()

const weixinSaomaUrl = () => {
  uni.navigateTo({
    url: '/pages/index/saoma?type=huandian',
  })
}
const weixinSaoma = () => {
  uni.scanCode({
    success: (res) => {
      console.log('扫描结果:', res)
      if (res.errMsg === 'scanCode:ok') {
        uni.showToast({
          title: '扫码成功',
          icon: 'success',
        })
      } else {
        uni.showToast({
          title: '扫码失败',
          icon: 'error',
        })
      }
    },
    fail: (err) => {
      console.error('扫码失败:', err)
      uni.showToast({
        title: '扫码失败',
        icon: 'error',
      })
    },
  })
}

const openCharging = () => {
  uni.navigateTo({
    url: '/pages/batterySwap/index',
  })
}
</script>

<style lang="scss">
@import '../styles/category.scss';
</style>
